<template>
  <div class="app-container">
    <section>
      <div class="contentBox">
        <div class="infoWrap">
          <!-- <img  src="form.staff_avatar" alt="" > -->
          <vs-uploading
            readonly="readonly"
            width="55px"
            v-model="form.staff_avatar"
          ></vs-uploading>
          <span>{{ this.form.staff_name }}</span>
        </div>
        <div class="content">
          <el-form
            ref="form"
            :model="form"
            :rules="rules"
            class="form"
            label-width="110px"
          >
            <el-form-item label="投诉建议内容：" style="width: 100%">
              <el-input
                v-model="form.content"
                readonly="readonly"
                type="textarea"
                :rows="4"
              ></el-input>
            </el-form-item>
            <!-- <el-form-item label="投诉建议图片：" style="width:100%">
                            <div class="imgbox">
                                <img src="https://willmid-img.oss-cn-shanghai.aliyuncs.com/2021/08/27/_20210622160448.jpg" alt="">
                            </div>
                        </el-form-item> -->
            <el-form-item
              label="投诉建议图片："
              style="width: 100%"
              ref="images"
              prop="images"
            >
              <vs-uploading
                readonly="readonly"
                width="120px"
                v-model="form.images"
              ></vs-uploading>
            </el-form-item>
            <el-form-item style="width: 100%" class="replyBox">
              <div class="replyInfo">
                <p>回复管理者：{{ this.form.admin_realname }}</p>
                <p>回复时间：{{ this.form.reply_time | parseTime }}</p>
                <p>回复内容：</p>
              </div>
            </el-form-item>
            <el-form-item style="width: 100%" class="replyBox">
              <el-input
                v-model="form.reply"
                ref="getValue"
                :readonly="type==1"
                type="textarea"
                :rows="4"
              ></el-input>
            </el-form-item>
          </el-form>
          <div style="margin-top: 40px" v-if="type!=1">
            <el-button type="primary" style="width: 100px" @click="save"
              >确定回复</el-button
            >
            <el-button style="width: 100px" @click="$router.go(-1)"
              >取消回复</el-button
            >
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
import { mapState } from "vuex";
import VsUploading from "../../components/VsUploading";
export default {
  components: {
    VsUploading,
  },
  data() {
    var url = (rule, value, callback) => {
      // 图片验证
      if (!this.form.url) {
        //hasFmt设置为true/false
        callback(new Error("请上传图片!"));
      } else {
        callback();
      }
    };
    return {
        type:0,
      form: {
        role_id: "",
        username: "",
        realname: "",
        mobile: "",
        id: "",
        password: "",
        url: "",
        date: "",
        content: "",
        admin_realname: "",
        reply: "",
        reply_time: "",
        images: "",
        id: "",
        staff_avatar: "",
      },
      rules: {
        role_id: [{ required: true, message: "请选择角色", trigger: "blur" }],
      },
      roleList: [],
      tableData1: [],
      feedbackRepl: [
        {
          id: "",
          content: "",
        },
      ],
      sta: [],
    };
  },
  async created() {
    if (this.$route.query.id) {
      this.form.id = this.$route.query.id;
      this.type = this.$route.query.type;
      await this.tofeedback();
    }
    this.$route.meta.title = this.$route.query.title;
  },
  computed: {
    ...mapState("user", ["userInfo"]),
  },
  mounted() {},
  methods: {
    async tofeedback() {
      //获取列表
      this.loading = true;
      let { code, data } = await this.$Http.feedback(this.form);
      this.loading = false;
      // 获取当前时间
      let date = new Date();
      let nowDate = this.utils.getNowDate(date);
      console.log(nowDate, "nowDatenowDatenowDate");
      if (code) {
        this.form = {
          admin_realname: data.admin_realname
            ? data.admin_realname
            : this.userInfo.username,
          content: data.content,
          create_time: data.create_time,
          is_anonymous: data.is_anonymous,
          reply: data.reply,
          reply_admin_id: data.reply_admin_id,
          reply_time: data.reply_time ? data.reply_time : nowDate,
          staff_id: data.staff_id,
          staff_name: data.staff_name,
          staff_number: data.staff_number,
          status: data.status,
          store_id: data.store_id,
          type: data.type,
          user_id: data.user_id,
          user_type: data.user_type,
          images: data.images.split(','),
          id: data.id,
          staff_avatar: data.staff_avatar,
        };
        this.tableData1 = data.data;
        console.log(88888888, this.form);
      }
    },
    async feedbackReply() {
      this.loading = true;
      let { code, data } = await this.$Http.feedbackReply(this.feedbackRepl);
      this.loading = false;
      if (code) {
        this.feedbackRepl = data;
        this.feedbackRepl.content = this.$refs.getValue.value;
        this.feedbackRepl.id = this.form.id;
      }
    },
    async save() {
      if (!this.form.reply) {
        this.$message.error("回复内容不能为空");
        return;
      }
      let subData = {};
      subData.content = this.$refs.getValue.value;
      subData.id = this.form.id;
      this.loading = true;
      let { code } = await this.$Http.feedbackReply(subData);
      this.loading = false;
      if (code) {
        this.$message.success("回复成功");
        this.$router.go(-1);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  section {
    .contentBox {
      background: #fff;
      border-radius: 8px;
      padding: 0 24px 20px;
      min-width: 900px;
      min-height: calc(100vh - 165px);
      .infoWrap {
        padding-top: 20px;
        display: flex;
        align-items: center;
        img {
          width: 60px;
          height: 60px;
          border-radius: 50%;
          object-fit: cover;
          margin-right: 20px;
        }
        span {
          color: #333;
          font-size: 16px;
        }
      }
      .title {
        line-height: 70px;
        font-size: 18px;
        font-weight: 600;
        color: #383b40;
        .el-icon-close {
          cursor: pointer;
        }
      }
    }
    .content {
      max-width: 800px;
      height: 100%;
      .form {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
      }
    }
  }
}
::v-deep {
  .el-input {
    width: 250px;
  }
}
.imgbox {
  display: flex;
  flex-wrap: wrap;
  img {
    width: 100px;
    height: 100px;
    object-fit: cover;
    margin-right: 20px;
  }
}
.replyBox {
  margin-left: 0;
  margin-bottom: 0;
  ::v-deep {
    .el-form-item__content {
      margin-left: 0 !important;
    }
  }
}
.replyInfo {
  background: #f1f1f1;
  padding: 0 10px;
  p {
    color: #999;
    font-size: 16px;
    margin: 0;
    line-height: 33px;
  }
}
</style>